package com.chenfan.ccp.plug.business.aspect;

import com.chenfan.ccp.utils.TraceIdUtil;
import lombok.SneakyThrows;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.MDC;

/**
 * @author xutong
 */
@Aspect
public class TraceIdAspect {

    @Around(value = "@annotation(com.xxl.job.core.handler.annotation.XxlJob)")
    @SneakyThrows
    public Object around(ProceedingJoinPoint point) {
        Object proceed;
        MDC.put("traceId", TraceIdUtil.getUUID());
        try {
            proceed = point.proceed();
        }finally {
            MDC.clear();
        }

        return proceed;
    }

}
